home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.2 KB | 86 lines | [TEXT/ttxt] |
- -- Filename:
- -- wrapper.sx
-
- -- Other Files Required:
- -- None
-
- -- Purpose:
- -- Create a Controller subclass which wraps projectiles around in a space.
-
- -- Specialized Classes:
- -- None
-
- -- Instructions to User:
- -- Class Wrapper ensures that when objects move off of a space, they reappear
- -- on the other side.
-
- -- Author:
- -- Steve Mayer
-
- -- Class Wrapper is a Controller which controls Projectiles. The Wrapper checks
- -- its controllees at each tickle to see if they have moved outside of the space. If
- -- they have, they are automatically "wrapped" around to the other side.
-
- in module InternetFish
-
- class Wrapper (Controller)
- instance variables
- state
- client
- end
-
- method init self {class Wrapper} #rest args #key state: client: ->
- (
- apply nextMethod self targetCollection:(new Array) args
- append self.protocols Projectile
- self.state := state
- self.client := client
- return self
- )
-
- -- Method tickle is called by the parent space at each clock tick.
- -- It iterates through controllees and wraps them if they are outside the boundary.
-
- method tickle self {class Wrapper} c ->
- (
- if self.state = @standalone then (
- local leftEdge
- local topEdge
- local rightEdge := self.space.boundary.x2
- local bottomEdge := self.space.boundary.y2
- -- Iterate through controllees
- for n in self do
- (
- leftEdge := (self.space.boundary.x1 - n.width)
- topEdge := (self.space.boundary.y1 - n.height)
- -- Check if object is past any edges.
- if (n.x < leftEdge) do (n.x := rightEdge)
- if (n.x > rightEdge) do (n.x := leftEdge)
- if (n.y < topEdge) do (n.y := bottomEdge)
- if (n.y > bottomEdge) do (n.y := topEdge)
- )
- ) else (
- local rightEdge := self.space.boundary.x2
- local bottomEdge := self.space.boundary.y2
- -- Iterate through controllees
- local n := self[1]
- local leftEdge := (self.space.boundary.x1 )
- local topEdge := (self.space.boundary.y1)
-
- if self.state = @own and n.x < leftEdge then (
- self.state := @losing
- noteLosing self.client
- ) else if self.state = @losing then (
- if (n.x + n.width) < leftEdge then (
- self.state := @lost
- noteLost self.client
- ) else if (n.x > leftEdge) then (
- noteGotBack self.client
- ) else
- noteStillLosing self.client
- )
- )
- )
-
- -- End of class definition for Wrapper
-